// -----------------------------------------------
// Author:     code34 nicolas_boiteux@yahoo.fr
// Edited by:  Neumatic
// Warcontext: Send variables to join players (JIP)
// -----------------------------------------------
if (!isServer) exitWith {};

private [
	"_count",
	"_ok",
	"_name",
	"_playerid",
	"_variables"
];

_name = _this select 1;

diag_log format ["WARCONTEXT: PLAYER %1 CONNECTING", _name];

_ok = true;
_count = 0;

// Wait that jip client is initialized
while {_ok} do {
	if (_name in wcplayerready) then {
		_ok = false;
	};
	if (_count > 500) then {
		_ok = false;
	};
	_count = _count + 1;
	sleep 1;
};

{
	if (name _x == _name) then {
		_playerid = owner _x;
	};
	sleep 0.01;
} foreach playableUnits;

_variables = [
	"wcobjective",
	"wcnuclearzone",
	"wchostage",
	"wccfgpatches",
	"wcday",
	"wcweather",
	"wcselectedzone",
	"wcradioalive",
	"wcskill",
	"wclevel",
	"wcmissioncount",
	"wcmotd",
	"wcenemykilled",
	"wccivilkilled",
	"wconelife",
	"wcinteam",
	"wcteleport"
];

{
	[_x, "client", _playerid] call WC_fnc_publicvariable;
	sleep 0.2;
} foreach _variables;

diag_log format ["WARCONTEXT: PLAYER %1 CONNECTED", _name];